<?php


namespace App\Admin\Extensions\Show;


class UnSerialize extends \Encore\Admin\Show\AbstractField
{

    /**
     * @inheritDoc
     */
    public function render($arg = '')
    {
        // 返回任意可被渲染的内容
        /************************用户************************/
        if( $arg == 'allCoin' ){
            //总品鉴金
            $this->value = \DB::table('users_balance_logs')->where('uid', $this->model->id)->whereIn('type', [1,2,3,4])->where('status', 1)->sum('money');
        }elseif( $arg == 'exchange' ){
            //兑换金额
            $this->value = \DB::table('users_withdrawal')->where('uid', $this->model->id)->whereIn('status', [0,1,2])->sum('money');
        }elseif( $arg == 'orderNum' ){
            //订单数
            $this->value = \DB::table('users_orders')->where('uid', $this->model->id)->count();
            /************************商家************************/
        }elseif( $arg == 'storeNum' ){
            //门店数
            $this->value = \DB::table('stores')->where('uid', $this->model->id)->count();
        }elseif( $arg == 'storeInfoNum' ){
            //外卖店铺数
            $this->value = \DB::table('stores_info')->where('uid', $this->model->id)->count();
        }elseif( $arg == 'storeOrderNum' ){
            //店铺订单数
            $this->value = \DB::table('users_orders')->where('store_uid', $this->model->id)->count();
        }elseif( $arg == 'returnAmount' ){
            //累计返现金额
            $this->value = \DB::table('settlement_order')->where('uid', $this->model->id)->where('status', 2)->sum('amount');
        }elseif( $arg == 'payAllAmount' ){
            //用户实付
            $this->value = \DB::table('users_orders')->where('store_uid', $this->model->id)->whereIn('status', [40, 50])->sum('amount');
        }elseif( $arg == 'notSettleAmount' ){
            //待结算金额
            $this->value = \DB::table('users_orders')->where('store_uid', $this->model->id)->whereIn('status', [35,40])->sum('settle_amount');
        }elseif( $arg == 'notSettleNum' ){
            //待结算订单
            $this->value = \DB::table('users_orders')->where('store_uid', $this->model->id)->whereIn('status', [35,40])->count();
        }elseif( $arg == 'todayPayAllAmount' ){
            //今日用户实付
            $this->value = \DB::table('users_orders')->where('store_uid', $this->model->id)->whereDate('created_at', date('Y-m-d'))->whereIn('status', [40,50])->sum('amount');
        }elseif( $arg == 'tomoPayAllAmount' ){
            //昨日用户实付
            $this->value = \DB::table('users_orders')->where('store_uid', $this->model->id)->whereDate('created_at', date('Y-m-d', strtotime('-1 day', time())))->whereIn('status', [40,50])->sum('amount');
        }elseif( $arg == 'todayReturnAmount' ){
            //今日返现金额
            $this->value = \DB::table('settlement_order')->where('uid', $this->model->id)->whereDate('created_at', date('Y-m-d'))->where('status', 2)->sum('amount');
        }elseif( $arg == 'tomoReturnAmount' ){
            //昨日返现金额
            $this->value = \DB::table('settlement_order')->where('uid', $this->model->id)->whereDate('created_at', date('Y-m-d', strtotime('-1 day', time())))->where('status', 2)->sum('amount');
        }elseif( $arg == 'todayStoreOrderNum' ){
            //今日店铺订单数
            $this->value = \DB::table('users_orders')->whereDate('created_at', date('Y-m-d'))->where('store_uid', $this->model->id)->count();
        }elseif( $arg == 'tomoStoreOrderNum' ){
            //昨日店铺订单数
            $this->value = \DB::table('users_orders')->whereDate('created_at', date('Y-m-d', strtotime('-1 day', time())))->where('store_uid', $this->model->id)->count();
        }elseif( $arg == 'friendNum' ){
            //好友数
            $this->value = \DB::table('users')->where('pid', $this->model->id)->count();
        }
        elseif( $arg == 'inviteCoin' ){
            //赚得好友乐淘币
            $this->value = \DB::table('users_balance_logs')->where('uid', $this->model->id)->where('type', 2)->where('status', 1)->sum("money");
        }
        elseif( $arg == 'source' ){
            //好友数
            if( $this->model->pid )
                $this->value = \DB::table('users')->where('id', $this->model->pid)->value('name')."好友/微信授权";
            else
                $this->value = "独立用户/微信授权";
        }

//        $this->value = $this->value == 0 ? '--':'';

        return $this->value;

    }
}